import Page
from Page import Personal
from Base.Base import Base
from selenium.webdriver.common.by import By


class PersonalAuthorizePage(Base):
    """
    个人中心授权页面
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.authorize_home_btn = (By.XPATH, Personal.RESOURCE_ID.format("ivHome"))

        # 左侧的返回键
        self.authorize_back_btn = (By.XPATH, Personal.RESOURCE_ID.format('ivBack'))

        # 车辆图片
        self.authorize_car_picture_icon = (By.XPATH, Personal.RESOURCE_ID.format("car_pic"))

        # 车牌号码
        self.authorize_car_number_title_text = (By.XPATH, Personal.RESOURCE_ID.format("tv_car_number"))

        # 车牌号
        self.authorize_car_number_text = (By.XPATH, Personal.RESOURCE_ID.format("tv_car_number_value"))

        # 无感支付标题
        self.authorize_feeless_payment_title_text = (By.XPATH, Personal.Feeless_payment_text.format(""))

        # 无感支付开启按钮
        self.authorize_feeless_payment_open_btn = (By.XPATH, Personal.Feeless_payment_btn.format(""))

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.authorize_home_btn)

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.authorize_back_btn)

    def get_car_picture(self):
        """
        获取车辆图片

        :return:
        """
        return self.find_element_o(self.authorize_car_picture_icon)

    def get_car_number_title(self):
        """
        获取车牌号码标题

        :return:
        """
        return self.find_element_o(self.authorize_car_number_title_text)

    def get_car_number(self):
        """
        获取车牌号码

        :return:
        """
        return self.find_element_o(self.authorize_car_number_text)

    def get_feeless_payment_title(self, index=1):
        """
        获取无感支付标题

        :return:
        """
        self.authorize_feeless_payment_title_text = (By.XPATH, Personal.Feeless_payment_text.format(index))
        return self.find_element_o(self.authorize_feeless_payment_title_text)

    def click_feeless_payment_open(self, index=1):
        """
        点击开启按钮

        :return:
        """
        self.authorize_feeless_payment_open_btn = (By.XPATH, Personal.Feeless_payment_btn.format(index))
        self.click_element(self.authorize_feeless_payment_open_btn)

    def is_display_authorize(self):
        """
        是否存在授权信息页

        :return: bool
        """
        return self.is_display(self.authorize_car_number_title_text )
